package com.mapper;

import com.mybatisflex.core.BaseMapper;
import com.entity.FUser;
import org.apache.catalina.User;
import org.apache.ibatis.annotations.*;

import java.util.List;

/**
 *  映射层。
 *
 * @author admin
 * @since 2024-05-14
 */
@Mapper
public interface FUserMapper extends BaseMapper<FUser> {

    // 根据ID查询后台用户
    @Select("SELECT * FROM f_user WHERE id = #{id}")
    FUser findById(Integer id);

    // 插入后台用户
    @Insert("INSERT INTO f_user(user_name, pwd, phone) VALUES (#{userName}, #{pwd}, #{phone})")
    int insertAdmin(FUser fUser);

    // 更新后台用户
    @Update("UPDATE f_user SET user_name = #{userName}, pwd = #{pwd}, phone = #{phone} WHERE id = #{id}")
    int updateAdmin(FUser fUser);

    // 删除后台用户（根据ID）
    @Delete("DELETE FROM f_user WHERE id = #{id}")
    int deleteAdminById(Integer id);

    // 查询所有后台用户
    @Select("SELECT * FROM f_user")
    List<FUser> findAllAdmins();

    // 根据用户名和密码查询后台用户（用于登录）
    @Select("SELECT * FROM f_user WHERE user_name = #{userName} AND pwd = #{pwd}")
    public FUser userLogin(FUser fUser);

    @Insert("INSERT INTO f_user(user_name,pwd,phone) values (#{userName},#{pwd},#{phone})")
    int insertUser(FUser fUser);
}
